﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;

namespace Win32Test
{
    class Program
    {
        
        [DllImport("user32.dll", EntryPoint = "SendMessage", CharSet = CharSet.Unicode)]
        internal static extern IntPtr SendMessage(IntPtr hwnd, int msg, IntPtr wParam, String lParam);

        [DllImport("User32.dll")]
        static extern void SetCursorPos(int X, int Y);

        [DllImport("User32.dll")]
        public static extern bool GetCursorPos(ref Point pt);

        static void Main(string[] args)
        {
            GamePadService.GamePadServiceClient gamePadService = new GamePadService.GamePadServiceClient();
            int i = 0;

            while (true)
            {
                System.Threading.Thread.Sleep(500);
                try
                {
                    int mouseX = Convert.ToInt32(gamePadService.GetMouseX());
                    int mouseY = Convert.ToInt32(gamePadService.GetMouseY());
                    Point pt = new Point(0, 0);
                    if (GetCursorPos(ref pt))
                    {
                        SetCursorPos(mouseX*1280/540, mouseY*1280/300);
                    }
                }
                catch (Exception ex)
                {
                    Console.Out.WriteLine("Error");
                }
                
            }
        }
    }
}
